package com.learn.jackson.annotation.jsonProperty;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.annotation.OptBoolean;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author HuangChao
 * @since 2025/6/8 21:06
 */
@Data
@EqualsAndHashCode
public class JsonPropertyEntity2 {
    @JsonProperty(index = 1)
    private final Long id;
    @JsonProperty(index = 0)
    @JsonSetter(nulls = Nulls.SKIP)
    private String name;

    public JsonPropertyEntity2(
        @JsonProperty(value = "id", index = 1) Long id,
        @JsonProperty(
            value = "name2"
            // 反序列化时值是否必须存在  与 @JsonCreator 结合才能生效
            // , required = false
            // 与 required 一样
            , isRequired = OptBoolean.TRUE
            /*
             * READ_ONLY : 只在序列化时生效
             * WRITE_ONLY : 只在反序列化时生效
             * READ_WRITE : 读写都生效
             * AUTO : 通过属性的 setter/getter 方法自动探测
            */
            , access = JsonProperty.Access.AUTO
        )
        String name
    ) {
        this.id = id;
        this.name = name;
    }
}
